package org.wanho.servlet;

import org.wanho.util.CookieUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author：汤小洋
 * Date：2023-04-24 10:55
 * Description：<描述>
 */
@WebServlet("/main")
public class MainServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = CookieUtil.findByName("username", req);
        String password = CookieUtil.findByName("password", req);

        if("admin".equals(username) && "123".equals(password)){
            req.getRequestDispatcher("/WEB-INF/pages/main.jsp").forward(req,resp);
        }else{
            CookieUtil.removeCookie("username",resp);
            CookieUtil.removeCookie("password",resp);
            resp.sendRedirect(req.getContextPath()+"/test05.jsp");
        }

    }
}
